doseresNMA antidep/drnma.tab.converge.R

# table of rhat and effective sample size
require(dplyr)
converge.table <- function(m=drnma_RE,
                           ref.lab='placebo',
                           drug.lab=levels(antidep$drug), ...){
    
    # data
    ndrugs <- length(drug.lab)
    ref.index <- which(levels(as.factor(drug.lab))==ref.lab)
    labs <- drug.lab[drug.lab!=ref.lab]
    
    mm <- m$BUGSoutput$summary %>% 
      t() %>% 
      data.frame() %>% 
      select(!ends_with(paste0(ref.index,'.'))& # exclude ref
               starts_with('beta1.')|
               !ends_with(paste0(ref.index,'.'))& # exclude ref
               starts_with('beta2.')
               )%>% 
      t()%>% 
      data.frame()
  row.names(mm) <- c(paste0('beta1.',labs),paste0('beta2.',labs))
  
  # table to return
  tibble(Parameters=row.names(mm), 
         Rhat=mm[,'Rhat'],
         'Effective Sample Size'=as.integer(mm[,'n.eff'])
         )
}
htx-r/doseresNMA documentation built on Jan. 28, 2021, 5:32 a.m.